package com.lc.soft.controller;

import com.lc.soft.entity.CommonParameter;
import com.lc.soft.entity.DistrictEntity;
import com.lc.soft.service.IDistrictService;
import com.lc.soft.utils.ResponseResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("district")
@Log4j2
public class DistrictController {

    private IDistrictService districtService;

    @Autowired
    public DistrictController(IDistrictService districtService) {
        this.districtService = districtService;
    }

    @RequestMapping("create")
    public ResponseResult create(DistrictEntity districtEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.create(districtEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("update")
    public ResponseResult updateMap(DistrictEntity districtEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.update(districtEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("enable")
    public ResponseResult enable(DistrictEntity districtEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.enable(districtEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("disable")
    public ResponseResult disable(DistrictEntity districtEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.disable(districtEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("delete")
    public ResponseResult delete(DistrictEntity districtEntity) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.delete(districtEntity);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findDistrictListByCondition")
    public ResponseResult findDistrictListByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.findDistrictListByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findDistrictTreeByCondition")
    public ResponseResult findDistrictTreeByCondition(CommonParameter commonParameter) {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.findDistrictTreeByCondition(commonParameter);
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }

    @RequestMapping("findProvinceAndCityTree")
    public ResponseResult findProvinceAndCityTree() {
        Long start = new Date().getTime();
        ResponseResult responseResult = districtService.findProvinceAndCityTree();
        Long end = new Date().getTime();
        log.info("间隔时间：" + (end - start) + "ms");
        return responseResult;
    }
}
